/*************************************************************
 * File: Pagination.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Feb 3, 2013
 * Description: 
 ************************************************************/

package snow.core.persistence;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;

/**
 * 分页数据载体，为
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
public final class Pagination implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7371034115057699326L;
	
	private Long totalCounts; // 记录总条数
	private List<Object> records; // 数据记录

	public Pagination(Collection<?> collection, Long totalCounts) {
		this.records = Collections.emptyList();
		if (CollectionUtils.isNotEmpty(collection)) {
			this.records = new ArrayList<Object>(collection);
		}
		this.totalCounts = totalCounts;
	}
	
	public Pagination(Object[] records, Long totalCounts) {
		this(ArrayUtils.isEmpty(records) ? Collections.emptyList() : Arrays.asList(records), totalCounts);
	}

	public Object[] getRecords() {
		return this.records.toArray();
	}

	public Long getTotalCounts() {
		return this.totalCounts;
	}

	public void setRecords(Object[] records) {
	}

	public void setTotalCounts(Long totalCounts) {
	}
}
